{% extends "layout.html" %}

{% block title %}Création achat mobile {% endblock %}

{% block content %}

<script>

$(document).ready(function() {
	$(":checkbox").change(function() {
		var id = this.value;
		var id_incompat = this.id;
		
		// créer la variable avec les incompatibilités
		var chkId = '';
		$('.chk:checked').each(function() {
		  chkId += this.id + ",";
		});
		// retire la dernière virgule
		chkId = chkId.slice(0,-1);
		//créé le tableau
		var array = chkId.split(",");
		//console.log(array);
		//console.log(id);
		
		//compare les incompatibilités
		if(jQuery.inArray(id, array) != -1) {
			console.log("est incompatible");
			if (document.getElementById(this.id).checked) 
			{
				alert("Options Incompatibles");
				document.getElementById("creation").disabled = true; //désactive le bouton de validation
			}else{
				document.getElementById("creation").disabled = false; //active le bouton de validation
			}
		} else {
			console.log("est compatible");
			document.getElementById("creation").disabled = false; //active le bouton de validation
		}
	});
});
</script>

<form method="post" class="form-horizontal" >

	<div class="row">
	<div class="span11">
	<a href="achat-offre-fixe" class="btn btn btn-primary"><i class="icon-plus-sign icon-white"></i> Voir la liste </a>
	  <fieldset>
		<legend align="center">Nouvel Achat Offre Fixe {{type}} </legend>
	  </fieldset>
    </div>
	 <!-- Première colonne -->
	<div class="span5">
    
	  <fieldset>
{% if type == ""  %} 
    <div class="control-group">
        <label class="control-label" for="type">Type</label>
        <div class="controls">
            <select name="type" size="1" onchange='submit()'/>
                <option value="">Selectionnez...</option>
                {% if not(session.niveauAuth=='2')and not(session.niveauAuth=='4')and not(session.niveauAuth=='6')and not(session.niveauAuth=='7')and not(session.niveauAuth=='9') %}
                <option value="vga" {% if offre.type == "vga" %}selected{% endif %}>VGA</option>
                <option value="vga/num" {% if offre.type == "vga/num" %}selected{% endif %}>VGA numeris</option>
                {% endif %}
                {% if not(session.niveauAuth=='2')and not(session.niveauAuth=='4')and not(session.niveauAuth=='5')and not(session.niveauAuth=='6')and not(session.niveauAuth=='7')and not(session.niveauAuth=='8')and not(session.niveauAuth=='9') %}
                <option value="voip" {% if offre.type == "voip" %}selected{% endif %}>VOIP</option>
                <option value="xdsl" {% if offre.type == "xdsl" %}selected{% endif %}>Xdsl</option>
                {% endif %}
            </select>
        </div>
    </div> 
{% else %}
	
	
      <div class="control-group">
		<label class="control-label" for="code_artice">Code article</label>
        <div class="controls">
		<div class="input-prepend">
		   <input name="code_article" type="text" value=""/> 
           <input name="type" type="hidden" value="{{type}}"/> 
		</div>
	  </div>
	  </div>
      
	  <div class="control-group">
		<label class="control-label" for="nom">Nom </label>
        <div class="controls">
		<div class="input-prepend">
		   <input name="nom" type="text" value=""/> 
		</div>
	  </div>
	  </div>
      
{% if type != 'xdsl' %}  
    <div class="control-group">
        <label class="control-label" for="temps_min">Temps minutes</label>
        <div class="controls">
            <div class="input-prepend">
            	<input name="temps_min" type="text" value=""/> 
            </div>
        </div>
    </div>
      
	  <div class="control-group">
			<label class="control-label" for="jours">Jours</label>
		<div class="controls">
			   <select name="jours" size="1" />
	           	<option value="">Selectionnez...</option>
				  <option value="7/7" {% if offre.jours == "7/7" %}selected{% endif %}>7 jours sur 7</option>
				  <option value="5/7" {% if offre.jours == "5/7" %}selected{% endif %}>5 jours sur 7</option>
	              <option value=""> </option>
	
				</select>
			</div>
		  </div>
	  
	   <div class="control-group">
			<label class="control-label" for="horaires">Horaires</label>
			<div class="controls">
			   <select name="horaires" size="1" />
	           	<option value="">Selectionnez...</option>
				  <option value="24/24" {% if offre.horaires == "24/24" %}selected{% endif %}>24h sur 24</option>
				  <option value="8/19" {% if offre.horaires == "8/19" %}selected{% endif %}>8h à 19h</option>
	              <option value=""> </option>
	
				</select>
			</div>
		  </div>
		  
		       <div class="control-group">
   <label class="control-label">Type de forfait</label>
      	<div class="controls">
      		<label class="checkbox inline" for="fixe">
     			<input type="checkbox" id="fixe" name ="fixe" value="x"> Fixe
 			</label>
			<label class="checkbox inline"for="mobile">
  				<input type="checkbox" id="mobile" name ="mobile" value="x"> Mobile
			</label>
		</div>  
	  </div>
	
{% else %}
    			<input name="temps_min" type="hidden" value=""/> 
                <input name="jours" type="hidden" value=""/> 
                <input name="horaires" type="hidden" value=""/> 
                <input name="fixe" type="hidden" value=""/> 
                <input name="mobile" type="hidden" value=""/> 
{% endif %}    
      <div class="control-group">
		<label class="control-label" for="prix_ha">Prix d'achat </label>
		<div class="controls">
		   <input name="prix_ha" type="text" value=""/> 
		</div>
	  </div>
      
      <div class="control-group">
		<label class="control-label" for="options_choisies">Options a inclure </label>
    {% for option in liste_options %}
    
        <div class="controls">
        	<input name="options_choisies[]" type="checkbox" id="{{option.incompatibilite}}" value="{{option.id}}" class="chk"/> {{option.nom}} <br>
        </div>
     
    {% endfor %}
    </div>
      	<!-- 
       <div class="control-group">
		<label class="control-label" for="prix_avec_equipement">Prix avec équipement</label>
        <div class="controls">
		<div class="input-prepend">
           <input name="prix_avec_equipement" type="text" value=""/> 
		</div>
	  </div>
	  </div>
-->	  
	  
{% endif %}
	</fieldset>

	</div>
	</div>
	
	
		<div class="form-actions">
		<span>Action après validation</span>
		<br/>
		  <select name="action">
			<option value="achat-offre-fixe">Afficher la liste </option>
			<!--<option value="">Créer une commande pour un client</a></option>-->
			<option value="achat-offre-fixe-creation">Saisir une nouvelle offre</option>
		  </select>
		<br/><br/>
         
		<button type="submit" class="btn btn-primary" name="creation" id="creation">Création</button>
        <button type="reset" class="btn " name="annuler">Annuler</button>
        
		</div>

	
</form>

{% endblock %}
	
